﻿/**
 * 日志管理
 */
var log4js = require('log4js'),
    mkdirp = require('mkdirp'),
    path = require('path');

var logDir = path.join(__dirname, '..', 'logs');

//console.log('创建日志目录', new Date().getTime());
mkdirp.sync(logDir);

log4js.configure({

    appenders: [
        {
            type: "file",
            filename: path.join(logDir, 'log.log'),
            pattern: "_yyyy-MM-dd",
            maxLogSize: 1048576,
            backups: 3,
            category: 'dateFileLog'

        },
        {
            type: "file",
            filename: path.join(logDir, 'sql.log'),
            pattern: "_yyyy-MM-dd",
            maxLogSize: 1048576,
            backups: 3,
            category: 'sqlLog'

        }
    ],
    replaceConsole: true,   //替换console.log
    levels: {
        dateFileLog: process.env.LogLevel || 'debug',
        sqlLog: process.env.LogLevel || 'debug'
    }
});


var dateFileLog = log4js.getLogger('dateFileLog');
var sqlLog = log4js.getLogger('sqlLog');

module.exports = {
    logger: dateFileLog,
    sqlLogger: sqlLog
}